<link rel="stylesheet" href="assets/common/plugins/umeditor/themes/default/css/umeditor.css">
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">编辑文章</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">文章标题 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="article[title]"
                                           value="<?= $model['title'] ?>" placeholder="请输入标题" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">文章分类 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select name="article[category_id]"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择', maxHeight: 400}">
                                        <option value=""></option>
                                        <?php if (isset($catgory)): foreach ($catgory as $item): ?>
                                            <option value="<?= $item['category_id'] ?>"
                                                <?= $model['category_id'] == $item['category_id'] ? 'selected' : '' ?>><?= $item['name'] ?></option>
                                        <?php endforeach; endif; ?>
                                    </select>
                                    <small class="am-margin-left-xs">
                                        <a href="<?= url('content.article.category/add') ?>">去添加</a>
                                    </small>
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">所属景点 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select name="article[scenic_id]" required
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择景点分类', maxHeight: 400}">
                                        <option value=""></option>
                                        <?php if (isset($list)): foreach ($list as $v): ?>
                                            <option value="<?= $v['id'] ?>" <?php if($v['id']== $model['scenic_id']){echo 'selected';}?>><?= $v['scenic_name'] ?></option>
                                            
                                            
                                        <?php endforeach; endif; ?>
                                        
                                    </select>
                                    
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">文章作者 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select name="article[author]"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择', maxHeight: 400}">
                                        <option value=""></option>
                                        <?php if (isset($model['author'])): ?>
                                
                                               
                                                <option value="旅行官A" <?= $model['author'] == '旅行官A' ? 'selected' : '' ?>>旅行官A</option>
                                                <option value="旅行官B" <?= $model['author'] == '旅行官B' ? 'selected' : '' ?>>旅行官B</option>
                                                <option value="旅行官C" <?= $model['author'] == '旅行官C' ? 'selected' : '' ?>>旅行官C</option>    
                                        <?php endif; ?>
                                    </select>
                                    <small class="am-margin-left-xs">
                                        <a href="<?= url('content.article.category/add') ?>">去添加</a>
                                    </small>
                                </div>
                            </div>
                            
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">文章封面图 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <div class="am-form-file">
                                        <div class="am-form-file">
                                            <button type="button"
                                                    class="upload-file am-btn am-btn-secondary am-radius">
                                                <i class="am-icon-cloud-upload"></i> 选择图片
                                            </button>
                                            <div class="uploader-list am-cf">
                                                <div class="file-item">
                                                    <a href="<?= $model['image']['file_path'] ?>" title="点击查看大图"
                                                       target="_blank">
                                                        <img src="<?= $model['image']['file_path'] ?>">
                                                    </a>
                                                    <input type="hidden" name="article[image_id]"
                                                           value="<?= $model['image_id'] ?>">
                                                    <i class="iconfont icon-shanchu file-item-delete"></i>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">模板设置</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">模板选择 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="article[template]" value="1" data-am-ucheck
                                        <?php if($model['template'] == 1){echo 'checked';}?>>
                                        图文
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="article[template]" value="2" data-am-ucheck <?php if($model['template'] == 2){echo 'checked';}?>>
                                        视频
                                    </label>
                                </div>
                            </div>
                            <div class="am-form-group" id="video" style="display:<?php if($model['template'] == 1){echo 'none';}?>;">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">视频链接 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="article[video_src]"
                                           value="<?= $model['video_src'] ?>" placeholder="请输入视频链接" required>
                                </div>
                            </div>
                            <div class="am-form-group am-padding-top" id="photo" style="display:<?php if($model['template'] == 2){echo 'none';}?>;">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">文章内容 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <!-- 加载编辑器的容器 -->
                                    <textarea id="container" name="article[content]"
                                              type="text/plain"><?= $model['content'] ?></textarea>
                                </div>
                            </div>

                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">挂载商品</div>
                            </div> 
                            <div class="am-form-group am-padding-top">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">选择商品 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <?php $num = 0;?>
                                    <?php if (isset($ticket)): foreach ($ticket as $v):?>
                                    <input name="article[ticket_id][]" type="checkbox" value="<?=$v['id']?>" 
                                    <?php if(in_array($v['id'],$model['ticket_id'])){
                                                echo 'checked';        
                                            }
                                    ?>
                                    />&nbsp;<?=$v['name'];?>
                                        &nbsp;
                                    <?php $num++;?>
                                    <?php if($num % 3 == 0){echo '<br>';}?>
                                    <?php endforeach; endif;?>
                                    
                                </div>
                            </div>                    
                            

                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">其他设置</div>
                            </div>   
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">文章状态 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="article[status]" value="1" data-am-ucheck
                                            <?= $model['status'] == 1 ? 'checked' : '' ?>>
                                        显示
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="article[status]" value="0" data-am-ucheck
                                            <?= $model['status'] == 0 ? 'checked' : '' ?>>
                                        隐藏
                                    </label>
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">横幅展示 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="article[is_banner]" value="1" data-am-ucheck
                                            <?= $model['is_banner'] == 1 ? 'checked' : '' ?>>
                                        是
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="article[is_banner]" value="0" data-am-ucheck
                                            <?= $model['is_banner'] == 0 ? 'checked' : '' ?>>
                                        否
                                    </label>
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">文章排序 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" class="tpl-form-input" name="article[sort]"
                                           value="<?= $model['sort'] ?>" required>
                                    <small>数字越小越靠前</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                    </button>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- 图片文件列表模板 -->
<script id="tpl-file-item" type="text/template">
    {{ each list }}
    <div class="file-item">
        <a href="{{ $value.file_path }}" title="点击查看大图" target="_blank">
            <img src="{{ $value.file_path }}">
        </a>
        <input type="hidden" name="{{ name }}" value="{{ $value.file_id }}">
        <i class="iconfont icon-shanchu file-item-delete"></i>
    </div>
    {{ /each }}
</script>

<!-- 文件库弹窗 -->
<!-- {{include file="layouts/_template/file_library" /}} -->

<script src="assets/common/plugins/umeditor/umeditor.config.js?v=<?= $version ?>"></script>
<script src="assets/common/plugins/umeditor/umeditor.min.js"></script>
<script>
    $(function () {

        // 选择图片
        $('.upload-file').selectImages({
            name: 'article[image_id]'
        });

        // 富文本编辑器
        UM.getEditor('container', {
            initialFrameWidth: 375 + 15,
            initialFrameHeight: 600
        });

        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm();
        $("[name='article[template]").on("click",function () {
            if($(this).val() ==1 ){
                $("#video").css("display","none");
                $("#photo").show();
            }
            if($(this).val() == 2){
                $("#photo").css("display","none");
                $("#video").show();
            }
        })
    });
</script>
